<?php


namespace app\home\controller;


use app\base\BaseController;
use think\Exception;
use think\facade\Db;
use think\facade\View;

class SaleDetail extends BaseController
{
    protected $title = '销售明细';
    protected $table = 'sale_contract_detail';
protected $sType=1;
    public function index()
    {
        $param = $this->request->param();
        if (request()->isAjax()) {
            $where[] = ['scd.status', '=', 4];
            $where[] = ['scd.type', '=', $this->sType];

            if (isset($this->param['status']) && $this->param['status']) {
                $where[] = ['scd.status', '=', $this->param['status']];
            }
            if (isset($this->param['buyType']) && $this->param['buyType']) {//采购状态
                $where[] = ['scd.buyStatus', '=', $this->param['buyType']];
            }
            if (isset($this->param['outStatus']) && $this->param['outStatus']) {//出库状态
                $where[] = ['scd.outStatus', '=', $this->param['outStatus']];
            }
            if (isset($this->param['moneyStatus']) && $this->param['moneyStatus']) {//回款状态
                $where[] = ['sc.payStatus', '=', $this->param['moneyStatus']];
            }
            if (isset($this->param['stokType']) && $this->param['stokType']) {//锁定状态
                $where[] = ['scd.lockStatus', '=', $this->param['stokType']];
            }
            if (isset($this->param['name']) && $this->param['name']) {
                $where[] = ['py.name', 'like', '%' . $this->param['name'] . '%'];
            }
            if (isset($this->param['saleUnit']) && $this->param['saleUnit']) {
                $where[] = ['d.title', 'like', '%' . $this->param['saleUnit'] . '%'];
            }
            if (isset($this->param['saller']) && $this->param['saller']) {
                $where[] = ['ad.name', 'like', '%' . $this->param['saller'] . '%'];
            }
            if (isset($this->param['orderNum']) && $this->param['orderNum']) {
                $where[] = ['sc.orderNum', 'like', '%' . $this->param['orderNum'] . '%'];
            }
            if (isset($this->param['orderDate']) && $this->param['orderDate']) {
                $dates = explode('~', $this->param['orderDate']);
                $where[] = ['sc.orderDate', 'between', $dates];
            }
            $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
            $list = Db::name($this->table)
                ->alias('scd')
                ->leftJoin('sale_contract sc', 'sc.id=scd.orderId')
                ->leftJoin('purveyor py', 'py.id=sc.punterId')
                ->leftJoin('department d', 'd.id=sc.salesUnitId')
                ->leftJoin('admin ad', 'ad.id=sc.saleId')
                ->leftJoin('material_dossier md', 'md.id=scd.mdId')
                ->where($where)
                ->field('scd.*,py.name as pName,d.title as dName,ad.name as saleName,md.bar_code,md.name as mdName
                ,md.brand,md.specs,md.buyCode,md.unit,sc.orderDate,sc.orderNum as orderNum')
                ->order('scd.id DESC')
                ->paginate($rows)->each(function ($item) {
                    $buyContractId=Db::name('sale_contract_detail')->where('status',4)->where('saleContractDetailId',$item['id'])
                        ->column('orderId');
                    $item['cgcb'] = Db::name('sale_contract')->where('status','4')->where('id','in',$buyContractId)->sum('countMoney');
                    $item['cgcb']=$item['cgcb']?$item['cgcb']:0;

                    $item['hsml'] = $item['bjMoney']-$item['cgcb'];
                    $item['msmll'] = round( $item['hsml']/$item['bjMoney']*100,2);
                    $item['cgNum'] = Db::name('sale_contract_detail')
                        ->where('status', '=', 4)
                        ->where('saleContractDetailId', $item['id'])
                        ->where('type', '=', 2)
                        ->sum('bjNum');
                    $item['lockedNum'] = Db::name('sale_contract_lock')
                        ->where('status', '>', -1)
                        ->where('detailId', $item['id'])->sum('lockNum');
                    $buyContractDId=Db::name('sale_contract_detail')->where('status',4)
                        ->where('type',2)->where('saleContractDetailId',$item['id'])->column('id');
                    $item['inNum'] = Db::name('stock_order_detail')
                        ->where('status', '=', 2)
                        ->where('saleContractDetailId', "in", $buyContractDId)
                        ->where('mdId', $item['mdId'])
                        ->where('type', '=',3)
                        ->sum('num');
                    $item['outNum'] = Db::name('stock_order_detail')
                        ->where('status', '=', 2)
                        ->where('saleContractDetailId', $item['id'])
                        ->where('mdId', $item['mdId'])
                        ->where('type', '=', 1)
                        ->sum('num');
                    $item['refundNum'] = Db::name('stock_order_detail')
                        ->where('status', '=', 2)
                        ->where('saleContractDetailId', $item['id'])
                        ->where('mdId', $item['mdId'])
                        ->where('type', '=', 2)
                        ->sum('num');

                    return $item;
                });
            return table_assign(0, '', $list);
        } else {
            return view();
        }
    }

    public function lock()
    {
        $sdId = $this->param['sdId'] ?? '';

        if (request()->isPost()) {
            $data = $this->param['data'] ?? [];
            if (!$data){
                return  to_assign(1,'操作有误');
            }
            $salOrderId=Db::name('sale_contract_detail')
                ->where('id',$sdId)->value('orderId');
//            Db::name('sale_contract_lock')->where('detailId', $sdId)->update(['status' => -1, 'deleted' => time()]);
            $insData = [];
            foreach ($data as $v) {
                $insData[] =$lockData= [
                    'orderId' => $salOrderId,
                    'detailId' => $sdId,
                    'mdId' => $v['mdId'],
                    'wId' => $v['wId']??1,
                    'buyContactMxId' => $v['id'],
                    'buyContactId' => $v['orderId'],
                    'lockNum' => $v['thisLock'],
                    'create_time' => time(),
                    'update_time' => time()
                ];

//                if (isset($data['lockedId'])){
//                    unset($lockData['create_time']);
//                    if ($v['thisLock']){
//                        Db::name('sale_contract_lock')->where('id',$data['lockedId'])->update($lockData);
//                    }else{
//                        Db::name('sale_contract_lock')->where('id',$data['lockedId'])->update(['status'=>-1,'deleted'=>time()])   ;
//                    }
//                }else{
//                    Db::name('sale_contract_lock')->insert($lockData);
//                }

            }
            if ($insData) {
                Db::name('sale_contract_lock')->insertAll($insData);
                $num=Db::name('sale_contract_detail')->where('id',$sdId)->value('bjNum');
                $lockedNum= Db::name('sale_contract_lock')->where('status','>',-1)
                    ->where('sType',$this->sType)->where('detailId',$sdId)->count('lockNum');
                $upData=[];
                if ($lockedNum==0){
                    $upData=[
                        'lockStatus'=>1
                    ];
                }elseif ($lockedNum>=$num){
                    $upData=[
                        'lockStatus'=>3
                    ];
                }else{
                    $upData=[
                        'lockStatus'=>2
                    ];
                }
                Db::name('sale_contract_detail')->where('id',$sdId)->update($upData);
            }


            add_log('lock', $sdId, $this->param, $this->title . '锁定');
            return to_assign();
        } else {
            $sdInfo = Db::name($this->table)->where('id', $sdId)->find();
            view::assign('sdInfo', $sdInfo);

            return view('lock');
        }
    }

    public function toRefund()
    {
        $pType=2;
        $ids = $this->param['ids'] ?? '';
        if ($this->request->isPost()) {
            $punterId = $this->param['punterId'] ?? '';
            $mx = $this->param['mx'] ?? [];
            if (!$mx||!$punterId) {
                return to_assign(1, '参数缺失');
            }

            $mxId = $mx['mxid'] ?? [];
            $mdId = $mx['mdId'] ?? [];
            $wId = $mx['wId'] ?? [];
            $num = $mx['num'] ?? [];
            $saleContractOrder = $mx['saleContractOrder'] ?? [];
            Db::startTrans();
            try {
                $refoundData = [
                    'orderNum' => dJBHBySql('stock_order', 'orderNum', 'XSTH' . date('Ymd'), false, 1000),
                    'type' => $pType,
                    'punterId' => $punterId,
                    'createId' => $this->uid,
                    'departId' => $this->did,
                    'checkId' => $this->uid,
                    'kdCompany' => $this->param['kdCompany']??'',
                    'saveId' => $this->param['saveId']??0,
                    'kdOrderNum' => $this->param['kdOrderNum']??'',
                    'checkTime' => date('Y-m-d H:i:s'),
                    'status'=>2,
                    'create_time' => time(),
                    'update_time' => time(),
                ];
                $rId=Db::name('stock_order')->insertGetId($refoundData);
                $mxData=[];
                foreach ($mxId as $key=>$v){
                   $mxData[]= [
                      'orderId'=>  $rId,
                       'mdId'=>$mdId[$key],
                       'wId'=>$wId[$key],
                       'num'=>$num[$key],
                       'kcNum'=>0,
                       'occupyNum'=>0,
                       'status'=>2,
                       'saleContractOrder'=>$saleContractOrder[$key],
                       'saleContractDetailId'=>$mxId[$key],
                       'type'=>$pType,
                       'create_time' => time(),
                       'update_time' => time(),
                    ];
                }
                Db::name('stock_order_detail')->insertAll($mxData);
                add_log('toRefund', $ids, $this->param, $this->title . '锁定');
                Db::commit();
            }catch (\Exception $e){
                Db::rollback();
                return to_assign(1,'操作失败：'.$e->getMessage());
            }
            return  to_assign();

        } else {
            $warehouseList = Db::name('warehouse')->where('status', 1)->field('id,name')->select();
            view::assign('warehouse', $warehouseList);
            $list = Db::name($this->table)->where('scd.id', 'in', $ids)
                ->alias('scd')
                ->leftJoin('sale_contract sc','sc.id=scd.orderId')
                ->leftJoin('material_dossier md', 'md.id=scd.mdId')
                ->field('scd.*,sc.orderNum,md.bar_code,md.name as mdName,md.specs,md.unit,md.brand,md.buyCode')
                ->select();
            $punterList = Db::name('purveyor')->where('status', 1)
                ->where('dw_type', 2)
                ->field('id,name')->select();
            view::assign('punterList', $punterList);

            view::assign('pType', $pType);
            view::assign('list', $list);
            view::assign('ids', $ids);
            return view('form');
        }
    }
    public function toOut()
    {
        $pType=1;
        $ids = $this->param['ids'] ?? '';
        if ($this->request->isPost()) {
            $mx = $this->param['mx'] ?? [];
            $punterId = $this->param['punterId'] ?? '';
            if (!$mx||!$punterId) {
                return to_assign(1, '参数缺失');
            }
            $mxId = $mx['mxid'] ?? [];
            $mdId = $mx['mdId'] ?? [];
            $wId = $mx['wId'] ?? [];
            $num = $mx['num'] ?? [];
            $saleContractOrder = $mx['saleContractOrder'] ?? [];
            Db::startTrans();
            try {
                $refoundData = [
                    'orderNum' => dJBHBySql('stock_order', 'orderNum', 'XSCK' . date('Ymd'), false, 1000),
                    'type' => $pType,
                    'punterId' => $punterId,
                    'createId' => $this->uid,
                    'departId' => $this->did,
                    'checkId' => $this->uid,
                    'kdCompany' => $this->param['kdCompany']??'',
                    'saveId' => $this->param['saveId']??0,
                    'kdOrderNum' => $this->param['kdOrderNum']??'',
                    'checkTime' => date('Y-m-d H:i:s'),
                    'status'=>2,
                    'create_time' => time(),
                    'update_time' => time(),
                ];
                $rId=Db::name('stock_order')->insertGetId($refoundData);
                $mxData=[];
                foreach ($mxId as $key=>$v){
                    $mxData[]= [
                        'orderId'=>  $rId,
                        'mdId'=>$mdId[$key],
                        'wId'=>$wId[$key],
                        'num'=>$num[$key],
                        'kcNum'=>0,
                        'occupyNum'=>0,
                        'status'=>2,
                        'saleContractOrder'=>$saleContractOrder[$key],
                        'saleContractDetailId'=>$mxId[$key],
                        'type'=>$pType,
                        'create_time' => time(),
                        'update_time' => time(),
                    ];
                }
                Db::name('stock_order_detail')->insertAll($mxData);
                add_log('toOut', $ids, $this->param, $this->title . '锁定');
                Db::commit();
            }catch (\Exception $e){
                Db::rollback();
                return to_assign(1,'操作失败：'.$e->getMessage());
            }
            return  to_assign();

        } else {
            $warehouseList = Db::name('warehouse')->where('status', 1)->field('id,name')->select();
            view::assign('warehouse', $warehouseList);
            $list = Db::name($this->table)->where('scd.id', 'in', $ids)
                ->alias('scd')
                ->leftJoin('sale_contract sc','sc.id=scd.orderId')
                ->leftJoin('material_dossier md', 'md.id=scd.mdId')
                ->field('scd.*,sc.orderNum,md.bar_code,md.name as mdName,md.specs,md.unit,md.brand,md.buyCode')
                ->select();
            $punterList = Db::name('purveyor')->where('status', 1)
                ->where('dw_type', 2)
                ->field('id,name')->select();
            view::assign('punterList', $punterList);

            view::assign('pType', $pType);
            view::assign('list', $list);
            view::assign('ids', $ids);
            return view('form');
        }
    }
    public function toBuy()
    {
        $param = get_params();
        $saleDetailId=$param['ids']??'';

//        halt($saleDetailInfo);
        if (request()->isAjax()) {
            $param=$this->param;
            $mx=$param['mx']??[];
            unset($param['mx']);
            if (!$mx){
                return to_assign(1,'请添加明细');
            }
            if (!$param['punterId']||!$param['contactId']){
                return to_assign(1,'参数有误');
            }
            $mxId=$mx['mxid']??[];
            $mdId=$mx['mdId']??[];
            $bjNum=$mx['bjNum']??[];
            $bjPrice=$mx['bjPrice']??[];
            $taxMoney=$mx['taxMoney']??[];
            $noTaxPrice=$mx['noTaxPrice']??[];
            $noTaxMoney=$mx['noTaxMoney']??[];
            $bjMoney=$mx['bjMoney']??[];
            $bjTime=$mx['bjTime']??[];
            $remark=$mx['remark']??[];
            $proCode=$mx['proCode']??[];
            $saleContractOrderNum=$mx['saleContractOrderNum']??[];
            $saleContractDetailId=$mx['saleContractDetailId']??[];
            $param['update_time']=time();
            $countMoney=0;
            foreach ($bjMoney as $v){
                $countMoney+=$v;
            }
            $param['countMoney']=$countMoney;
            $id=$this->param['id']??0;
            $flow_list = Db::name('Flow')->where('id',$param['flow_id'])->value('flow_list');
            $flow = unserialize($flow_list);
            Db::startTrans();
            try {
                if ($id > 0) {
                    $param['isTax']=$param['isTax']??2;
                    Db::name('sale_contract')->strict(false)->field(true)->update($param);

                    Db::name('FlowStep')->where(['action_id'=>$param['id'],'type'=>4,'delete_time'=>0])->update(['delete_time'=>time()]);
                    Db::name('FlowRecord')->where(['action_id'=>$param['id'],'type'=>4,'delete_time'=>0])->update(['delete_time'=>time()]);
                    if (!isset($param['check_admin_ids'])) {
                        if($flow[0]['flow_type'] == 1){
                            //部门负责人
                            $leader = get_department_leader($this->uid);
                            if($leader == 0){
                                return to_assign(1,'审批流程设置有问题：当前部门负责人还未设置，请联系HR或者管理员');
                            }
                            else{
                                $param['check_admin_ids'] = $leader;
                            }
                        }
                        else if($flow[0]['flow_type'] == 2){
                            //上级部门负责人
                            $leader = get_department_leader($this->uid,1);
                            if($leader == 0){
                                return to_assign(1,'审批流程设置有问题：上级部门负责人还未设置，请联系HR或者管理员');
                            }
                            else{
                                $param['check_admin_ids'] = $leader;
                            }
                        }
                        else{
                            $param['check_admin_ids'] = $flow[0]['flow_uids'];
                        }
                        foreach ($flow as $key => &$value){
                            $value['action_id'] = $param['id'];
                            $value['sort'] = $key;
                            $value['type'] = 4;
                            $value['create_time'] = time();
                        }
                        //增加审核流程
                        Db::name('FlowStep')->strict(false)->field(true)->insertAll($flow);
                    }
                    else{
                        $flow_step = array(
                            'action_id' => $param['id'],
                            'type' => 4,
                            'flow_uids' => $param['check_admin_ids'],
                            'create_time' => time()
                        );
                        //增加审核流程
                        Db::name('FlowStep')->strict(false)->field(true)->insertGetId($flow_step);
                    }
//添加提交申请记录
                    $checkData=array(
                        'action_id' => $id,
                        'check_user_id' => $this->uid,
                        'content' => '重新提交申请',
                        'type' => 4,
                        'check_time' => time(),
                        'create_time' => time()
                    );
                    Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($checkData);

                    add_log('edit', $param['id'], $param,$this->title);
                    //发送消息通知
                    $msg=[
                        'from_uid'=>$this->uid,
                        'title'=>'合同审批',
                        'action_id'=>$id
                    ];
                    $users = $param['check_admin_ids'];
                    sendMessage($users,51,$msg,'home','BuyContract','add');
                } else {
                    $param['createId']=$this->uid;
                    $param['saleId']=$this->uid;
                    $param['type']=2;
                    $param['departId']=$this->did;
                    $param['create_time'] = time();
                    $param['check_status']=1;
                    $param['status']=3;
                    $id = Db::name('sale_contract')->strict(false)->field(true)->insertGetId($param);
                    if (!isset($param['check_admin_ids'])) {
                        if($flow[0]['flow_type'] == 1){
                            //部门负责人
                            $leader = get_department_leader($this->uid);
                            if($leader == 0){
                                return to_assign(1,'审批流程设置有问题：当前部门负责人还未设置，请联系HR或者管理员');
                            }
                            else{
                                $param['check_admin_ids'] = $leader;
                            }
                        }
                        else if($flow[0]['flow_type'] == 2){
                            //上级部门负责人
                            $leader = get_department_leader($this->uid,1);
                            if($leader == 0){
                                return to_assign(1,'审批流程设置有问题：上级部门负责人还未设置，请联系HR或者管理员');
                            }
                            else{
                                $param['check_admin_ids'] = $leader;
                            }
                        }
                        else{
                            $param['check_admin_ids'] = $flow[0]['flow_uids'];
                        }

                        foreach ($flow as $key => &$value){
                            $value['action_id'] = $id;
                            $value['sort'] = $key;
                            $value['type'] = 4;
                            $value['create_time'] = time();
                        }
                        //增加审核流程
                        Db::name('FlowStep')->strict(false)->field(true)->insertAll($flow);
                    }else{
                        $flow_step = array(
                            'action_id' => $id,
                            'type' => 4,
                            'flow_uids' => $param['check_admin_ids'],
                            'create_time' => time()
                        );
                        //增加审核流程
                        Db::name('FlowStep')->strict(false)->field(true)->insertGetId($flow_step);

                    }

                    add_log('add', $id, $this->param,$this->title);
                    //发送消息通知
                    $msg=[
                        'from_uid'=>$this->uid,
                        'title'=>'合同审批',
                        'action_id'=>$id
                    ];
                    $users = $param['check_admin_ids'];
                    sendMessage($users,51,$msg,'home','BuyContract','add');
                }
                foreach ($mdId as $key=> $m){
                    $mxData=[
                        'orderId'=>$id,
                        'mdId'=>$mdId[$key],
                        'bjNum'=>$bjNum[$key],
                        'bjPrice'=>$bjPrice[$key],
                        'type'=>2,
                        'taxMoney'=>$taxMoney[$key],
                        'noTaxPrice'=>$noTaxPrice[$key],
                        'noTaxMoney'=>$noTaxMoney[$key],
                        'bjMoney'=>$bjMoney[$key],
                        'status'=>3,
                        'remark'=>$remark[$key],
//                        'proCode'=>$proCode[$key],
                        'saleContractOrderNum'=>$saleContractOrderNum[$key]??'',
                        'saleContractDetailId'=>$saleContractDetailId[$key]??0,
                        'create_time'=>time(),
                        'update_time'=>time()
                    ];
                    if (isset($mxId[$key])&&$mxId[$key]){
                        unset($mxData['create_time']);
                        $mxData['id']=$mxId[$key];
                    }
                    Db::name('sale_contract_detail')->save($mxData);
                }

                Db::commit();
            }catch (\Exception $e){
                Db::rollback();
                return to_assign(1,'操作失败:'.$e->getMessage());
            }

            return to_assign();
        }
        else {
            $id = isset($param['id']) ? $param['id'] : 0;
            $saleDetailInfoList=Db::name($this->table)
                ->alias('scd')
                ->leftJoin('sale_contract sc', 'sc.id=scd.orderId')
                ->leftJoin('purveyor py', 'py.id=sc.punterId')
                ->leftJoin('department d', 'd.id=sc.salesUnitId')
                ->leftJoin('admin ad', 'ad.id=sc.saleId')
                ->leftJoin('material_dossier md', 'md.id=scd.mdId')
                ->where('scd.id','in',$saleDetailId)
                ->field('scd.*,sc.tax,py.name as pName,d.title as dName,ad.name as saleName,md.bar_code,md.name as mdName
                ,md.brand,md.specs,md.buyCode,md.unit,sc.orderDate,sc.orderNum as orderNum')
                ->select();
            $detail=[];
            $mxList=[];
            if ($id > 0) {
                $detail = Db::name('sale_contract')->where('id', $id)->find();
                $mxList=Db::name('sale_contract_detail')->alias('qod')
                    ->leftJoin('material_dossier md','md.id=qod.mdId')
                    ->where('qod.status','>',-1)
                    ->where('qod.orderId',$id)
                    ->field('qod.*,md.name as mdName,md.buyCode,md.brand,md.specs,md.unit,md.bar_code')
                    ->select();
            }else{
                $detail['orderNum']=dJBHBySql('sale_contract','orderNum','CG'.date('Ymd'),false,1000);
            }
            $punterList=Db::name('purveyor')->where('status',1)
                ->where('dw_type',1)
                ->field('id,name')->select();
            view::assign('punterList',$punterList);
            $saleUniList=Db::name('department')->where('status',1)->field('id,title')->select();
            view::assign('saleUniList',$saleUniList);
            View::assign('mxList', $mxList);
            View::assign('id', $id);
            $is_check_admin = 0;
            $is_create_admin = 0;
            $check_record=[];
            if (!$id){
                $flows = get_cate_department_flows(25,$this->did);
            }else{
                $flows = Db::name('FlowStep')->where(['action_id'=>$detail['id'],'type'=>4,'sort'=>$detail['check_step_sort'],'delete_time'=>0])->find();
                $detail['check_user'] = '-';
                $detail['copy_user'] = '-';
                $check_user_ids = [];

                if($detail['check_status']==1){
                    if($flows['flow_type']==1){
                        $detail['check_user'] = '部门负责人';
                        $check_user_ids[]=get_department_leader($detail['createId']);
                    }
                    else if($flows['flow_type']==2){
                        $detail['check_user'] = '上级部门负责人';
                        $check_user_ids[]=get_department_leader($detail['createId'],1);
                    }
                    else{
                        $check_user_ids = explode(',',$flows['flow_uids']);
                        $check_user = Db::name('Admin')->where('id','in',$flows['flow_uids'])->column('name');
                        $detail['check_user'] = implode(',',$check_user);
                    }
                }

                if($detail['copy_uids'] !=''){
                    $copy_user = Db::name('Admin')->where('id','in',$detail['copy_uids'])->column('name');
                    $detail['copy_user'] = implode(',',$copy_user);
                }

                if($detail['createId'] == $this->uid){
                    $is_create_admin = 1;
                }

                $detail['create_user']=Db::name('admin')
                    ->where('id',$detail['createId'])->value('name');
                if(in_array($this->uid,$check_user_ids)){
                    $is_check_admin = 1;
                    //当前审核节点详情
                    $step = Db::name('FlowStep')->where(['action_id'=>$detail['id'],'type'=>4,'sort'=>$detail['check_step_sort'],'delete_time'=>0])->find();
                    if($step['flow_type'] == 4){
                        $check_count = Db::name('FlowRecord')->where(['action_id'=>$detail['id'],'type'=>2,'step_id'=>$step['id'],'check_user_id'=>$this->uid])->count();
                        if($check_count>0){
                            $is_check_admin = 0;
                        }
                    }
                }
                $check_record = Db::name('FlowRecord')->field('f.*,a.name,a.thumb')
                    ->alias('f')
                    ->join('Admin a', 'a.id = f.check_user_id', 'left')
                    ->where(['f.action_id'=>$detail['id'],'f.type'=>4])
                    ->order('check_time desc')
                    ->select()->toArray();
                foreach ($check_record as $kk => &$vv) {
                    $vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
                    $vv['status_str'] = '提交';
                    if($vv['status'] == 1){
                        $vv['status_str'] = '审核通过';
                    }
                    else if($vv['status'] == 2){
                        $vv['status_str'] = '审核拒绝';
                    }
                    if($vv['status'] == 3){
                        $vv['status_str'] = '撤销';
                    }
                }
            }
            View::assign('is_create_admin', $is_create_admin);
            View::assign('flows', $flows);
            View::assign('detail', $detail);
            View::assign('is_check_admin', $is_check_admin);
            View::assign('check_record', $check_record);
            View::assign('uid', $this->uid);
            view::assign('saleDetailInfoList',$saleDetailInfoList);
            $taxList=getOrderTax();
            View::assign('quoOrderTax',$taxList);
            return view('to_buy');
        }

    }
}